import axios from 'axios'
import {MyEmbeddings} from './myEmbeddings.js'

export class MyEmbeddings_test extends MyEmbeddings {
    async embed(text, maxRetries = 5, timeout = 5000) {
        let retryCount = 0;
        while (retryCount < maxRetries) {
            try {
                const res = await axios.post('http://43.134.44.205:30626/main_cli', {
                    "type": "passage",
                    "text": text
                }, {
                    proxy: {
                        host: 'localhost',
                        port: 7890,
                    },
                    timeout: timeout,
                });
                return {
                    data: res.data.para_embs[0]
                };
            } catch (error) {
                retryCount++;
            }
        }
        throw new Error(`达到最大重试次数(${maxRetries}次)`);
    }
}
